package com.migo.mongo.service.impl;

import com.migo.dao.impl.MongoBaseDaoImpl;
import com.migo.entity.ShOrderInfoEntity;
import com.migo.mongo.entity.AfterSaleMongo;
import com.migo.mongo.service.AfterSaleMongoService;
import com.migo.service.SysUserService;
import com.migo.utils.DateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Wes on 2018/11/14.
 */
@Repository
public class AfterSaleMongoServiceImpl extends MongoBaseDaoImpl<AfterSaleMongo> implements AfterSaleMongoService {

    @Autowired
    MongoTemplate mongoTemplate;


//    @Autowired
//    private SysUserService sysUserService;

    @Override
    public void saveAfterLog(ShOrderInfoEntity orderInfo, String desc) {
//        SysUserEntity user = sysUserService.queryObject(getUserId());
        AfterSaleMongo mongo = new AfterSaleMongo();
        BeanUtils.copyProperties(orderInfo,mongo);
        mongo.setAddTime(DateUtil.getNow());
//        mongo.setSysUser(user.getUsername());
        mongo.setDesc(desc);
        mongoTemplate.insert(mongo);
    }

    @Override
    public List<AfterSaleMongo> queryList(String orderId) {
        Query query = Query.query(Criteria.where("orderId").is(orderId));
        List<AfterSaleMongo> datas = mongoTemplate.find(query, AfterSaleMongo.class);
        return datas;
    }
}
